<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公共代码')" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="ggDm-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                代码名称：<input type="text" name="ddmc"/>
                            </li>
                            <li>
                                是否有效：<select name="isValid" th:with="type=${@dict.getType('biz_is_valid')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="biz:ggDm:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editTab()" shiro:hasPermission="biz:ggDm:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:ggDm:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />

    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('biz:ggDm:edit')}]];
        var removeFlag = [[${@permission.hasPermi('biz:ggDm:remove')}]];
        var detailFlag = [[${@permission.hasPermi('biz:ggDm:detail')}]];
        var seTypes = [[${@dict.getType('biz_se_type')}]];
        var isOpens = [[${@dict.getType('biz_is_open')}]];
        var prefix = ctx + "biz/ggDm";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "公共代码",
                detailUrl: prefix + "/detail/unit/{id}",
                columns: [{
                    checkbox: true
                },
                    {
                        field : 'id',
                        title : 'ID'
                    },
                    {
                        field : 'dmmc',
                        title : '代码名称'
                    },
                    {
                        field : 'dm',
                        title : '代码'
                    },
                    {
                        field : 'dmtype',
                        title : '代码类型'
                    },
                    {
                        field : 'val',
                        title : '字段值'
                    },
                    {
                        field: 'isDeleted',
                        title: '删除标志',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var isDeleted = '';
                            switch(row.isDeleted){
                                case '1':
                                    isDeleted='已删除';
                                    break;
                                default:
                                    isDeleted='未删除';
                            }
                            return isDeleted;
                        }
                    },
                    {
                        field: 'isValid',
                        title: '是否有效',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return statusTools(row);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detailTab(\'' + row.id + '\')"><i class="fa fa-file-text"></i>查看详情</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        });

        function statusTools(row) {
            if (row.isValid == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        function disable(id) {
            $.modal.confirm("确认要停用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
            })
        }

        function enable(id) {
            $.modal.confirm("确认要启用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
            })
        }
    </script>

</body>
</html>